// TableView.h : interface of the CTableView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_TABLEVIEW_H__2B1AA971_10DE_45AC_A6AE_D661749E3A75__INCLUDED_)
#define AFX_TABLEVIEW_H__2B1AA971_10DE_45AC_A6AE_D661749E3A75__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "McMyListView.h"
#include "TableViewMsg_AllType.h"
#include "TableViewMsg_Property.h"
#include "TableViewMsg_SubType.h"
#include "TableViewMsg_SubNode.h"

class CTableView : public McMyListView
{
protected: // create from serialization only
	CTableView();
	DECLARE_DYNCREATE(CTableView)

// Attributes
public:
	CNodeClientDoc* GetDocument();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTableView)
	public:
//	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual void OnInitialUpdate(); // called first time after construct
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CTableView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CTableView)
	afx_msg void OnDestroy();
	//}}AFX_MSG
	afx_msg LRESULT OnListAddItem(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnListDeleteItem(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnListGridDataChanged(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnListGetHistory(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnNodeChanged(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnNodeMsgAllType(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnNodeMsgProperty(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnNodeMsgSubType(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnNodeMsgSubNode(WPARAM wparam, LPARAM lparam);
	afx_msg LRESULT OnNodeServiceStatuChanged(WPARAM wparam, LPARAM lparam);

	DECLARE_MESSAGE_MAP()
private:
	friend class McMsgBase;
	friend class McMsgAllType;
	friend class McMsgProperty;
	friend class McMsgSubType;
	friend class McMsgSubNode;
	
	MsAddr addr_;
	long instance_no_;
	bool bNode_;
	long nodeId_;
	long propertyId_;

public:
	McMsgAllType msg_alltype_;
	McMsgProperty msg_property_;
	McMsgSubType msg_subtype_;
	McMsgSubNode msg_subnode_;
	MessageBuffer_Command_node_c buffer_alltype_;
	MessageBuffer_Command_node_c buffer_property_;
	MessageBuffer_Command_node_c buffer_subtype_;
	MessageBuffer_Command_node_c buffer_subnode_;
	MessageBuffer_Command_node_c* current_buffer_ptr_;

	virtual void get_obj_ref_name_map(long refType, map<long, string>& objIdName);
	virtual void get_cell_ref_nodes(const Ms_NodeId_PropertyId& np, vector<long>& refObjs);
};

#ifndef _DEBUG  // debug version in TableView.cpp
inline CNodeClientDoc* CTableView::GetDocument()
   { return (CNodeClientDoc*)m_pDocument; }
#endif
void add_none_exist_info(char* buff, char* buff_end, const set<long>& noExistIds, const map<long, string>& deleteObject);
void messagebox_noexist_node(const MsAddr& addr, const char* pCmdDesc, const set<long>& nodeIds);

class McAckDeleteType : public Mc_ack_default_delete_type
{
	virtual void on_exception(long pktype, const map<string, string>& context, long exceptionNo, const string& reason);
	virtual void on_ack(const map<string, string>& context);
	virtual void on_exception_Mex_Simple(const map<string, string>& context, const SIMPLE_EXCEPTION_NO& exNo);
	virtual void on_exception_Mex_Id_No_Exist(const map<string, string>& context, const set<long> & noExistIds);
	virtual void on_exception_Mex_Depend_Property_Exist(const map<string, string>& context, const map<long, set<long> > & dependPropertyIds);
	MsAddr addr_;
	map<long, string> deleteObject_;
public:
	McAckDeleteType(const MsAddr& addr, const map<long, string>& deleteObject);
};
class McAckDeleteProperty : public Mc_ack_default_delete_property
{
	virtual void on_exception(long pktype, const map<string, string>& context, long exceptionNo, const string& reason);
	virtual void on_ack(const map<string, string>& context);
	virtual void on_exception_Mex_Id_No_Exist(const map<string, string>& context, const set<long> & noExistIds);
	MsAddr addr_;
	map<long, string> deleteObject_;
public:
	McAckDeleteProperty(const MsAddr& addr, const map<long, string>& deleteObject);
};

class McAckDeleteNode : public Mc_ack_default_delete_node
{
	virtual void on_exception(long pktype, const map<string, string>& context, long exceptionNo, const string& reason);
	virtual void on_ack(const map<string, string>& context);
	virtual void on_exception_Mex_Id_No_Exist(const map<string, string>& context, const set<long> & noExistIds);
	virtual void on_exception_Mex_Depended_Error(const map<string, string>& context, bool bIsChildren, const set<long> & problemNodes);
	MsAddr addr_;
	map<long, string> deleteObject_;
public:
	McAckDeleteNode(const MsAddr& addr, const map<long, string>& deleteObject);
};

class McAckGetNodePropertyValueHistory : public Mc_ack_default_get_node_property_history_value
{
	MsAddr addr_;
	bool bNode_;
	long nodeId_;
	long propertyId_;
	long lDataType_;
	PROPERTY_STYLE propStyle_;
	MsDateTime dtBegin_;
	MsDateTime dtEnd_;
	long interval_;
	CTableView* pTableView_;
	virtual void on_ack(const map<string, string>& context, const map<MsDateTime, vector<char> > & result);
	virtual void on_exception_Mex_NodeId_PropertyId_No_Exist(const map<string, string>& context, const set<Ms_NodeId_PropertyId> & noExist);
public:
	McAckGetNodePropertyValueHistory(const MsAddr& addr, bool bNode, long nodeId, long propertyId, 
		const MsDateTime& dtBegin, const MsDateTime& dtEnd, long interval,
		long lDataType, PROPERTY_STYLE propStyle,
		CTableView* pTableView);
};
/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TableView_H__2B1AA971_10DE_45AC_A6AE_D661749E3A75__INCLUDED_)
